import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();

        int[] num = new int[n];

        for (int i = 0; i < n; i++) {
            num[i] = scanner.nextInt();
        }

        Solution solution = new Solution();
        System.out.println(solution.findSmallestInteger(num, m));
    }
}

class Solution {
    public int findSmallestInteger(int[] nums, int value) {
        int n = nums.length;
        int[] array = new int[value];

        for (int i = 0; i < n; i++) {
            array[(nums[i] % value + value) % value]++;
        }

        int res = 0;
        while(array[res % value] > 0){
            array[res % value]--;
            res++;
        }
        return res;
    }
}